﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Bus;
using BonsaiScrum.Core.Command;
using BonsaiScrum.Core.Domain;
using BonsaiScrum.Core.Infrastructure;
using BonsaiScrum.Core.Persistance;


namespace BonsaiScrum.Core.CommandHandlers
{
    public class CreateNewUserHandler : ICommandHandler<CreateNewUser>
    {
        private ILogger _logger;
        private IDomainRepository _domainRepository;

        public CreateNewUserHandler(ILogger logger, IDomainRepository domainRepository)
        {
            _logger = logger;
            _domainRepository = domainRepository;
        }


        public void Handle(CreateNewUser message)
        {
            _logger.Debug("A new user named '" + message.FirstName + " " + message.LastName + "' has been submitted, and his User ID is '" + message.Name + "'.");

            var user = new User(message.Name, message.Password, message.FirstName, message.LastName, message.PermitionLv);

            _domainRepository.Add(user);
        }

    }
}
